local skel = fk.CreateSkill {
  name = "emo__guili",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__guili"] = "归离",
  [":emo__guili"] = "锁定技，其他角色于其回合外获得牌后，须于当前回合结束时弃置等量牌，若是你的回合，你摸一张牌。",

  ["@emo__guili-turn"] = "归离",

  ["$emo__guili1"] = "当归、当归，日暮南山鸟倦飞。",
  ["$emo__guili2"] = "凤非梧桐不栖，小女遍寻城中未见一木。",
}

skel:addEffect(fk.TurnEnd, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(skel.name) then
      return table.find(player.room.alive_players, function (p)
        return p:getMark("@emo__guili-turn") > 0
      end)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      local n = p:getMark("@emo__guili-turn")
      if n > 0 then
        room:askToDiscard(p, {min_num = n, max_num = n, skill_name = skel.name, include_equip = true, cancelable = false})
        if not player.dead and target == player then
          player:drawCards(1, skel.name)
        end
      end
    end
  end,
})

skel:addEffect(fk.AfterCardsMove, {
  can_refresh = function (self, event, target, player, data)
    return player:hasShownSkill(skel.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.to and move.to ~= player and move.toArea == Card.PlayerHand then
        if not move.to.dead and move.to.phase == Player.NotActive then
          player.room:addPlayerMark(move.to, "@emo__guili-turn", #move.moveInfo)
        end
      end
    end
  end,
})

return skel
